#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

long long arr1[1010][1010];
long long rem[1010][1010];
long long ans;
int main()
{
	/*vector<vector<int>> vv;
	int r;
	cin >> r;
	vv.reserve(r + 2);
	int tmp;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j <= i ; j++) {
			cin >> tmp;
			vv[i].push_back(tmp);
		}
	}*/
	int r;
	cin >> r;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j <= i; j++) {
			scanf("%lld", &arr1[i][j]);
		}
	}
	rem[0][0] = arr1[0][0];
	for (int i = 0; i < r - 1; i++) {
		for (int j = 0; j <= i; j++) {
			rem[i+1][j] = max(rem[i+1][j], arr1[i + 1][j] + rem[i][j]);
			rem[i+1][j + 1] = max(rem[i+1][j + 1], arr1[i + 1][j + 1] + rem[i][j]);
		}
	}
	for (int i = 0; i < r; i++) {
		ans = max(ans, rem[r - 1][i]);
	}
	cout << ans << endl;
	return 0;
}